<?php
class Perbuatan_model extends MY_Model {
	
    function Perbuatan_model(){
    	parent::MY_Model();
        $this->table_name = "perbuatan";
        $this->table_fields = array('perb_id','perb_tgl_lapor','perb_tgl_kejadian', 'perb_tempat_kejadian',
        	'perb_keterangan','perb_status','perb_status_change','lapor_id','perb_poster');
    }
    
    function select_last_entry($search_key=false, $where=false, $limit=10, $offset=0, $orderby=""){
    	if ($search_key){
    		if (!is_array($search_key)) $search_key = array($search_key);
			
			$qq = '';
			foreach($search_key as $kk){
				foreach($this->table_fields as $ff){
					$qq .= ($qq? " OR " : "").$this->table_name.".$ff LIKE '%$kk%'";
				}
			}
			$this->where("($qq)");
    	}
    	if ($where) $this->where($where);
    	if ($orderby){
    		$this->order_by($orderby);
    	}
    	
    	return $this->get($limit, $offset);
    }
        
    function select_by_id($id){
    	return $query = $this->db->get_where($this->table_name, array('perb_id' => $id));
    }
    
	function get_last_id(){
    	$this->db->select_max($this->table_fields[0]);
    	$rr = $this->db->get($this->table_name);
    	$rr = (array)$rr->row();
    	return $rr[$this->table_fields[0]];
    }
}